package com.nahan.secondapplication.goodsdetail.fragment;


import android.animation.ObjectAnimator;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.nahan.secondapplication.R;


/**
 * 商品评论界面
 * A simple {@link Fragment} subclass.
 */
public class CommentFragment extends Fragment {

    private  ImageView img;
    private Button bt_xuan;


    public CommentFragment() {
        // Required empty public constructor
    }


    private static CommentFragment fragment = null;

    public static CommentFragment newInstance() {
        if (fragment == null) {
            fragment = new CommentFragment();
        }
        return fragment;
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view=inflater.inflate(R.layout.fragment_comment, container, false);
        img = (ImageView)view.findViewById(R.id.img);
        bt_xuan = (Button)view.findViewById(R.id.bt_xuan);
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        bt_xuan.setOnClickListener(v ->
                {
                    img.setPivotX(img.getWidth() / 2);//设置指定旋转中心点X坐标
                    img.setPivotY(0);//设置指定旋转中心点y坐标，
                    ObjectAnimator animator = ObjectAnimator.ofFloat(img, "rotation",
                            0F, 30F,0f,-30f,0f,20f,0f,-10f,0f,0f);//这里的意思是依次左右旋转一定的角度
                    animator.setDuration(1500);
                    animator.start();
                }
                );
    }
}
